package com.shanzmoo.admin.web;


import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.manager.FactoryOrderMananger;
import com.shanzmoo.db.produce.entity.dto.FactoryOrderQueryDto;
import com.shanzmoo.db.produce.entity.vo.FactoryOrderDetailVo;
import com.shanzmoo.db.produce.entity.vo.FactoryOrderPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 生产订单 前端控制器
 * </p>
 *
 * @author Gzhao
 * @since 2020-12-15
 */
@Api(tags = "门店-门店生产单管理")
@RestController
@RequestMapping("/api/produce/factoryOrder")
public class FactoryOrderController {

    @Autowired
    private FactoryOrderMananger factoryOrderMananger;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<FactoryOrderPageVo>> pageList(@Valid @RequestBody FactoryOrderQueryDto queryDto) {
        queryDto.setOutletId(CurrentUserCache.getOutletId());
        SResponse<PageRespBase<FactoryOrderPageVo>> re = factoryOrderMananger.getPageList(queryDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "生产单明细")
    @GetMapping("/details")
    public SHttpResponse<List<FactoryOrderDetailVo>> details(@ApiParam(value = "生产单号") @RequestParam(value = "productionNo") String productionNo){
        SResponse<List<FactoryOrderDetailVo>> re = factoryOrderMananger.details(productionNo);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "刷机完成")
    @GetMapping("/finish")
    public SHttpResponse<Boolean> finish(@ApiParam(value = "生产单号") @RequestParam(value = "productionNo") String productionNo){
        SResponse<Boolean> re = factoryOrderMananger.finish(productionNo);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "取消分配")
    @GetMapping("/cancel")
    public SHttpResponse<Boolean> cancel(@ApiParam(value = "生产单号") @RequestParam(value = "productionNo") String productionNo){
        SResponse<Boolean> re = factoryOrderMananger.cancel(productionNo);
        return SHttpResponse.transform(re);
    }
}
